<!DOCTYPE html>
<html>
  
<head>
  <meta charset="utf-8">
  <meta name="author" content="饿包子" />
  
  
  <title>功能与样式的参考和奇思妙想 | 饿包子博客</title>

  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

  
    <meta name="keywords" content="Javascript," />
  

  
  <meta name="description" content="在开发过程中，想必会遇到许许多多的问题，需要去查资料，当然我也遇到过，俗话说：好记性不如烂笔头。我相信写下一些笔记什么的应该也有相应的效果，也许它会非常繁琐，也许只是一两个字">

  
  
    <link rel="icon" href="/blog/images/xian.ico">
    <link rel="apple-touch-icon" href="/blog/images/Logo.png">
  

  
<link rel="stylesheet" href="/blog/css/Awesome.min.css">


  
<link rel="stylesheet" href="/blog/css/index.css">
<link rel="stylesheet" href="/blog/styles/components/highlight/highlight.css">


  
  
<script src="/blog/common/jquery.min.js"></script>

  
    
<script src="/blog/common/Av.min.js"></script>

  

  
    
<script src="/blog/common/MathJax.js"></script>

  

  
    
<script src="/blog/common/Valine.min.js"></script>

  

  

  <script>
  // theme-ad's config script
  // it can be used in every script
  
  window.AD_CONFIG = {
    leancloud: {"appid":"gE1EosDsVgB2slV4E92yPkcG-gzGzoHsz","appkey":"niR787UVTMyJQrR6gmOiJCKe","comment":true,"count":true},
    welcome: {"enable":false,"interval":30},
    start_time: "2018-06-10",
    passwords: ["a621ab606db2a11f63edc576a729843b8269250dc324206871d90635ac5e531c", ],
    is_post: true,
    lock: false,
    author: "饿包子",
    share: {"twitter":false,"facebook":false,"weibo":true,"qq":true,"wechat":false},
    mathjax: true,
    page_type: "",
    root: "/blog/"
  };
</script>

  
<script src="/blog/vendor/sha256.min.js"></script>
<script src="/blog/js/auth.js"></script>
<script src="/blog/js/index.js"></script>
<script src="/blog/vendor/qrcode.min.js"></script>


<meta name="generator" content="Hexo 5.4.2"></head>
  <body>
    <header class="site-header">
  <div class="site-header-brand">
    
      <span class="site-header-brand-title">
        <a href="/blog/">清风逐月</a>
      </span>
    
    
      <span class="site-header-brand-motto"> | 我思故我在</span>
    
  </div>
  <div class="site-header-right">
    <nav class="site-header-navigation">
      
        <a href="/blog/" target="_self">主页</a>
      
        <a href="/blog/archives/" target="_self">归档</a>
      
        <a href="/blog/tags/" target="_self">标签</a>
      
        <a href="/blog/categories/" target="_self">分类</a>
      
        <a href="/blog/categories/%E6%97%A5%E8%AE%B0" target="_self">日记</a>
      
    </nav>
    <div class="site-header-btn">
      
        <a href="https://github.com/lixianbin1/" target="_blank" id="site-github">
          <i class="fa fa-github-alt"></i>
        </a>
      
      <a href="javascript:void(0);" id="site-search">
        <i class="fa fa-search"></i>
      </a>
      <a href="javascript:void(0);" id="site-nav-btn">
        <i class="fa fa-ellipsis-v"></i>
      </a>
    </div>
  </div>
</header>
<nav class="table-content" id="site-nav">
  <div class="table-content-title">
    <span>导航</span>
  </div>
  <div class="table-content-main">
    <ol class="toc">
      
        <li class="toc-item">
          <a href="/blog/" target="_self">
            主页
          </a>
        </li>
      
        <li class="toc-item">
          <a href="/blog/archives/" target="_self">
            归档
          </a>
        </li>
      
        <li class="toc-item">
          <a href="/blog/tags/" target="_self">
            标签
          </a>
        </li>
      
        <li class="toc-item">
          <a href="/blog/categories/" target="_self">
            分类
          </a>
        </li>
      
        <li class="toc-item">
          <a href="/blog/categories/%E6%97%A5%E8%AE%B0" target="_self">
            日记
          </a>
        </li>
      
    </ol>
  </div>
</nav>
<div id="site-process"></div>
    <main>
      
  <div class="passage">
  <div class="passage-meta">
    <span>
      <i class="fa fa-calendar"></i>2019-06-21
    </span>
    
    
      <span>
        | <i class="fa fa-unlock-alt"></i>UNLOCK
      </span>
    
    <span>
       | <i class="fa fa-calendar"></i>更新时间:2020-12-8 9:23 
    </span>
  </div>
  <h1 class="passage-title">
    功能与样式的参考和奇思妙想
  </h1>
  
  <article class="passage-article">
    <h2 id="样式的处理参考"><a href="#样式的处理参考" class="headerlink" title="样式的处理参考"></a>样式的处理参考</h2><h3 id="内容进行强制换行"><a href="#内容进行强制换行" class="headerlink" title="内容进行强制换行"></a>内容进行强制换行</h3><p>浏览器需要容器的一个宽度用于内容的换行操作，但是当浏览器判断某些内容为一个单词的时候会拒绝换行</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="attribute">word-break</span>: break-word; <span class="comment">/*对单词进行强制拆分*/</span></span><br><span class="line"><span class="attribute">white-space</span>:pre-line;   <span class="comment">/*保证中文的换行，在碰到边后换行*/</span></span><br></pre></td></tr></table></figure>
<h3 id="禁止复制页面文字"><a href="#禁止复制页面文字" class="headerlink" title="禁止复制页面文字"></a>禁止复制页面文字</h3><p>当你需要长按操作的时候，或者单纯的不想出现复制文本的时候，你可以选择禁止用户复制页面上的文字</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">body</span> <span class="attr">onselectstart</span>=<span class="string">&quot;return false&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">body</span>&gt;</span></span><br></pre></td></tr></table></figure>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">*&#123;</span><br><span class="line">   -o-user-select: none;</span><br><span class="line">   -ms-user-select: none;</span><br><span class="line">   -moz-user-select: none;</span><br><span class="line">   -webkit-user-select: none;</span><br><span class="line">   user-select: none;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="对内容进行缩放处理"><a href="#对内容进行缩放处理" class="headerlink" title="对内容进行缩放处理"></a>对内容进行缩放处理</h3><p>很多时候，当页面字体太大（最小字体限制12px），会导致页面难看，需要使用缩放对内容进行缩放</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-class">.div</span>&#123;</span><br><span class="line">    <span class="attribute">transform</span>: <span class="built_in">scale</span>(<span class="number">0.5</span>);</span><br><span class="line">    <span class="attribute">transform-origin</span>: <span class="number">0</span> <span class="number">0</span>;</span><br><span class="line">    <span class="attribute">width</span>: <span class="number">200%</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 获取元素高度，将margin-bottom 设为原先高度的一半的负值</span></span><br><span class="line">$(<span class="string">&#x27;.set-li&#x27;</span>).<span class="title function_">map</span>(<span class="keyword">function</span>(<span class="params">e,a</span>)&#123;</span><br><span class="line">  <span class="keyword">var</span> height=$(a).<span class="title function_">height</span>()/<span class="number">2</span></span><br><span class="line">  $(a).<span class="title function_">css</span>(<span class="string">&#x27;margin-bottom&#x27;</span>,-height)</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>
<h3 id="点击获取焦点和tab获取焦点"><a href="#点击获取焦点和tab获取焦点" class="headerlink" title="点击获取焦点和tab获取焦点"></a>点击获取焦点和tab获取焦点</h3><p>默认只有表单类元素可以编辑，但是我们也可以让 p标签获取焦点和编辑，和快捷键tab获取光标</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">contenteditable</span>=<span class="string">&quot;true&quot;</span>&gt;</span>我可以被编辑<span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">tabindex</span>=<span class="string">&quot;0&quot;</span>&gt;</span>按下tab键，光标聚焦于我，索引是tab按下依次的顺序<span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br></pre></td></tr></table></figure>
<h3 id="单行多行文本的省略"><a href="#单行多行文本的省略" class="headerlink" title="单行多行文本的省略"></a>单行多行文本的省略</h3><p>在很多时候，我们需要实现单行文本省略和多行文本省略，但多平台的兼容却一直存在</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/* 单行文本省略 兼容性：IE7+ */</span></span><br><span class="line"><span class="selector-class">.textOver</span>&#123;</span><br><span class="line">  <span class="attribute">white-space</span>: nowrap;</span><br><span class="line">  <span class="attribute">overflow</span>: hidden;</span><br><span class="line">  <span class="attribute">text-overflow</span>: ellipsis;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">/* 多行文本省略 仅兼容 webkit 内核浏览器 */</span></span><br><span class="line"><span class="selector-class">.text</span>&#123;</span><br><span class="line">  <span class="attribute">word-wrap</span>: break-word;</span><br><span class="line">  <span class="attribute">white-space</span>: pre-line;</span><br><span class="line">  <span class="attribute">overflow</span>: hidden;</span><br><span class="line">  <span class="attribute">text-overflow</span>: ellipsis;</span><br><span class="line">  <span class="attribute">display</span>: -webkit-box;</span><br><span class="line">  -webkit-line-clamp: <span class="number">3</span>;</span><br><span class="line">  -webkit-box-orient: vertical;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>但是对于多平台兼容，还是有办法的，可能并不是特别完美 兼容性：IE8+</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">&quot;wrap&quot;</span>&gt;</span> <span class="tag">&lt;<span class="name">p</span>&gt;</span>asdaasdadas<span class="tag">&lt;/<span class="name">p</span>&gt;</span> <span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br></pre></td></tr></table></figure>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-class">.wrap</span> &#123;<span class="attribute">height</span>: <span class="number">40px</span>;<span class="attribute">line-height</span>: <span class="number">20px</span>;<span class="attribute">overflow</span>: hidden;&#125;</span><br><span class="line"><span class="selector-class">.wrap</span> <span class="selector-class">.text</span> &#123;<span class="attribute">float</span><span class="selector-pseudo">:right</span>;<span class="attribute">margin-left</span>:-<span class="number">20px</span>;<span class="attribute">width</span>:<span class="number">100%</span>;<span class="attribute">word-break</span>:break-all;&#125;</span><br><span class="line"><span class="selector-class">.wrap</span><span class="selector-pseudo">:before</span>&#123;<span class="attribute">float</span>: left;<span class="attribute">width</span>:<span class="number">20px</span>;<span class="attribute">content</span>: <span class="string">&#x27;&#x27;</span>;<span class="attribute">height</span>: <span class="number">40px</span>;&#125;</span><br><span class="line"><span class="selector-class">.wrap</span><span class="selector-pseudo">:after</span> &#123;</span><br><span class="line">  <span class="attribute">float</span>: right;</span><br><span class="line">  <span class="attribute">content</span>: <span class="string">&quot;...&quot;</span>;</span><br><span class="line">  <span class="attribute">height</span>: <span class="number">20px</span>;</span><br><span class="line">  <span class="attribute">line-height</span>: <span class="number">20px</span>;</span><br><span class="line">  <span class="attribute">width</span>: <span class="number">3em</span>;<span class="comment">/* 为三个省略号的宽度 */</span></span><br><span class="line">  <span class="attribute">margin-left</span>: -<span class="number">3em</span>;<span class="comment">/* 使盒子不占位置 */</span></span><br><span class="line">  <span class="attribute">position</span>: relative;<span class="comment">/* 移动省略号位置 */</span></span><br><span class="line">  <span class="attribute">left</span>: <span class="number">100%</span>;</span><br><span class="line">  <span class="attribute">top</span>: -<span class="number">20px</span>;</span><br><span class="line">  <span class="attribute">padding-left</span>: <span class="number">20px</span>;</span><br><span class="line">  <span class="attribute">background-image</span>:<span class="built_in">url</span>(<span class="string">&#x27;透明渐变图片&#x27;</span>); //用于覆盖尾部文本的透明渐变图片</span><br><span class="line">  <span class="attribute">background-repeat</span>: repeat-y;</span><br><span class="line">  <span class="attribute">background-size</span>: <span class="number">100%</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="CONSOLE-信息集"><a href="#CONSOLE-信息集" class="headerlink" title="CONSOLE 信息集"></a>CONSOLE 信息集</h3><p>可用于信息提示 </p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"># 输出信息</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;文字信息&#x27;</span>);</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">info</span>(<span class="string">&#x27;提示信息&#x27;</span>);</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">warn</span>(<span class="string">&#x27;警告信息&#x27;</span>);</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">error</span>(<span class="string">&#x27;错误信息&#x27;</span>);</span><br><span class="line"></span><br><span class="line"><span class="comment">// 当第一参数为false时，输出警告信息第二参数</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">assert</span>(<span class="literal">true</span>,<span class="string">&#x27;看不见&#x27;</span>)</span><br><span class="line"></span><br><span class="line"><span class="keyword">throw</span> <span class="keyword">new</span> <span class="title class_">Error</span>(<span class="string">&#x27;这是一个错误提示&#x27;</span>);</span><br><span class="line"><span class="keyword">throw</span> &#123; <span class="attr">name</span>: <span class="string">&#x27;参数错误&#x27;</span>, <span class="attr">message</span>: <span class="string">&#x27;data[0]不存在&#x27;</span>&#125;</span><br><span class="line"></span><br><span class="line"># 输出样式 （<span class="variable constant_">IE</span> 不支持）</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&quot;%c我要变色了&quot;</span>,<span class="string">&quot;color:blue;font-size:20px&quot;</span>)</span><br></pre></td></tr></table></figure>


<h2 id="页面动画的相关参考"><a href="#页面动画的相关参考" class="headerlink" title="页面动画的相关参考"></a>页面动画的相关参考</h2><h3 id="旋转卡片"><a href="#旋转卡片" class="headerlink" title="旋转卡片"></a>旋转卡片</h3><figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">@keyframes</span> flip &#123;</span><br><span class="line">  <span class="number">0%</span> &#123;</span><br><span class="line">    <span class="attribute">transform</span>: <span class="built_in">perspective</span>(<span class="number">2000px</span>) <span class="built_in">rotateY</span>(<span class="number">0</span>)</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="number">100%</span> &#123;</span><br><span class="line">    <span class="attribute">transform</span>: <span class="built_in">perspective</span>(<span class="number">2000px</span>) <span class="built_in">rotateY</span>(<span class="number">90deg</span>)</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">@keyframes</span> flip_out &#123;</span><br><span class="line">  <span class="number">0%</span> &#123;</span><br><span class="line">    <span class="attribute">transform</span>: <span class="built_in">perspective</span>(<span class="number">2000px</span>) <span class="built_in">rotateY</span>(-<span class="number">90deg</span>)</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="number">100%</span> &#123;</span><br><span class="line">    <span class="attribute">transform</span>: <span class="built_in">perspective</span>(<span class="number">2000px</span>) <span class="built_in">rotateY</span>(<span class="number">0</span>)</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="selector-class">.switching</span> &#123;</span><br><span class="line">  -webkit-<span class="attribute">transform</span>: <span class="built_in">perspective</span>(<span class="number">2000px</span>) <span class="built_in">rotateY</span>(-<span class="number">90deg</span>);</span><br><span class="line">  -webkit-<span class="attribute">animation</span>: flip .<span class="number">4s</span> linear,flip_out .<span class="number">4s</span> .<span class="number">41s</span> linear;</span><br><span class="line">  <span class="attribute">transform</span>: <span class="built_in">perspective</span>(<span class="number">2000px</span>) <span class="built_in">rotateY</span>(-<span class="number">90deg</span>);</span><br><span class="line">  <span class="attribute">animation</span>: flip .<span class="number">4s</span> linear,flip_out .<span class="number">4s</span> .<span class="number">41s</span> linear</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">// 点击后，给当前卡片添加 class &quot;switching&quot; ,<span class="number">0.4s</span> 后将将新卡片的背面显示，旧的隐藏。<span class="number">0.8s</span> 后 将&quot;switching&quot; 去除。</span><br></pre></td></tr></table></figure>
<h3 id="暂停效果"><a href="#暂停效果" class="headerlink" title="暂停效果"></a>暂停效果</h3><figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">@keyframes</span> play-state &#123;</span><br><span class="line">  <span class="number">0%</span> &#123;<span class="attribute">margin-left</span>: <span class="number">0</span>;&#125;</span><br><span class="line">  <span class="number">100%</span> &#123;<span class="attribute">margin-left</span>: <span class="number">200px</span>;&#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="selector-class">.play-state</span> &#123;</span><br><span class="line">  <span class="attribute">width</span>: <span class="number">100px</span>;<span class="attribute">height</span>: <span class="number">100px</span>;<span class="attribute">margin</span>: <span class="number">40px</span>;<span class="attribute">text-align</span>: center;</span><br><span class="line">  <span class="attribute">line-height</span>: <span class="number">94px</span>;<span class="attribute">border</span>: <span class="number">3px</span> solid <span class="number">#e1efde</span>;<span class="attribute">border-radius</span>: <span class="number">50%</span>;</span><br><span class="line">  <span class="attribute">animation</span>: play-state <span class="number">3s</span> linear infinite;<span class="attribute">cursor</span>: pointer;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="selector-class">.play-state</span><span class="selector-pseudo">:hover</span> &#123;</span><br><span class="line">  <span class="attribute">animation-play-state</span>: paused; <span class="comment">/*关键*/</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>


<h2 id="图片的相关处理"><a href="#图片的相关处理" class="headerlink" title="图片的相关处理"></a>图片的相关处理</h2><h3 id="图片的上传预览"><a href="#图片的上传预览" class="headerlink" title="图片的上传预览"></a>图片的上传预览</h3><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">input</span> <span class="attr">id</span>=<span class="string">&quot;upload&quot;</span> <span class="attr">type</span>=<span class="string">&quot;file&quot;</span> /&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">img</span> <span class="attr">id</span>=<span class="string">&quot;preview&quot;</span> <span class="attr">src</span>=<span class="string">&quot;&quot;</span> <span class="attr">alt</span>=<span class="string">&quot;预览&quot;</span>/&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">script</span>&gt;</span><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript"><span class="keyword">const</span> upload = <span class="variable language_">document</span>.<span class="title function_">querySelector</span>(<span class="string">&quot;#upload&quot;</span>);</span></span><br><span class="line"><span class="language-javascript"><span class="keyword">const</span> preview = <span class="variable language_">document</span>.<span class="title function_">querySelector</span>(<span class="string">&quot;#preview&quot;</span>);</span></span><br><span class="line"><span class="language-javascript">upload.<span class="property">onchange</span> = <span class="keyword">function</span>(<span class="params"></span>) &#123;</span></span><br><span class="line"><span class="language-javascript">  <span class="keyword">const</span> file = upload.<span class="property">files</span>[<span class="number">0</span>]; <span class="comment">//File对象</span></span></span><br><span class="line"><span class="language-javascript">  <span class="keyword">const</span> src = <span class="variable constant_">URL</span>.<span class="title function_">createObjectURL</span>(file); </span></span><br><span class="line"><span class="language-javascript">  preview.<span class="property">src</span> = src;</span></span><br><span class="line"><span class="language-javascript">&#125;;</span></span><br><span class="line"><span class="language-javascript"></span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br></pre></td></tr></table></figure>
<h3 id="大图从模糊到清晰"><a href="#大图从模糊到清晰" class="headerlink" title="大图从模糊到清晰"></a>大图从模糊到清晰</h3><p>但图片过大的时候，网速慢的时候，图片会呈现断片式加载一截一截的显示，显的比较难看。可以先显示压缩过的模糊的预览图片，在通过new Image() 的方式加载图片，当图片加载好后在替换页面上的图片</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">img</span> <span class="attr">src</span>=<span class="string">&quot;19.img&quot;</span>/ <span class="attr">data-url</span>=<span class="string">&quot;http://xianbin.cf/img/banner/191105.jpg&quot;</span> <span class="attr">class</span>=<span class="string">&quot;vague&quot;</span>&gt;</span></span><br></pre></td></tr></table></figure>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-class">.vague</span>&#123;<span class="attribute">filter</span>:<span class="built_in">blur</span>(<span class="number">2px</span>);<span class="attribute">transition</span>:all <span class="number">0.7s</span>;<span class="attribute">width</span>:<span class="number">100%</span>;&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">function</span> <span class="title function_">set</span>(<span class="params">a</span>)&#123;</span><br><span class="line">    <span class="keyword">var</span> url=$(a).<span class="title function_">attr</span>(<span class="string">&#x27;data-url&#x27;</span>)</span><br><span class="line">    <span class="keyword">var</span> img=<span class="keyword">new</span> <span class="title class_">Image</span>();</span><br><span class="line">    img.<span class="property">src</span>=url;</span><br><span class="line">    img.<span class="property">onload</span>=<span class="keyword">function</span>(<span class="params"></span>)&#123;</span><br><span class="line">        $(a).<span class="title function_">attr</span>(<span class="string">&#x27;src&#x27;</span>,url)</span><br><span class="line">        $(a).<span class="title function_">removeClass</span>(<span class="string">&#x27;vague&#x27;</span>)</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="title function_">set</span>(<span class="string">&#x27;.vague&#x27;</span>)</span><br></pre></td></tr></table></figure>
<h3 id="图片动态加载loading"><a href="#图片动态加载loading" class="headerlink" title="图片动态加载loading"></a>图片动态加载loading</h3><p>设置图片加载中的时候以loading 替代</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">function</span> <span class="title function_">load</span>(<span class="params">view,src</span>)&#123;</span><br><span class="line">    <span class="built_in">setTimeout</span>(<span class="keyword">function</span>(<span class="params"></span>)&#123;</span><br><span class="line">        <span class="keyword">let</span> img=<span class="keyword">new</span> <span class="title class_">Image</span>()</span><br><span class="line">        img.<span class="property">src</span>=src</span><br><span class="line">        img.<span class="property">onload</span>=<span class="keyword">function</span>(<span class="params"></span>)&#123;</span><br><span class="line">            <span class="keyword">let</span> box=<span class="variable language_">document</span>.<span class="title function_">getElementById</span>(view)</span><br><span class="line">            box.<span class="property">src</span>=src</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;,<span class="number">0</span>)</span><br><span class="line">&#125;</span><br><span class="line"><span class="title function_">load</span>(<span class="string">&#x27;2018A&#x27;</span>,<span class="string">&#x27;https://clubimg..jpg&#x27;</span>)</span><br></pre></td></tr></table></figure>

<h2 id="滚动条的相关处理方式"><a href="#滚动条的相关处理方式" class="headerlink" title="滚动条的相关处理方式"></a>滚动条的相关处理方式</h2><h3 id="滚动条的hover显示"><a href="#滚动条的hover显示" class="headerlink" title="滚动条的hover显示"></a>滚动条的hover显示</h3><p>滚动条只有鼠标悬浮在上的时候出现,且元素不出现缩放，重点在于子元素宽度需要比父级小,且使用 margin来处理距离</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-class">.div1</span>&#123;<span class="comment">/* 父级 */</span> <span class="attribute">width</span>:<span class="number">200px</span>; <span class="attribute">height</span>:<span class="number">200px</span>; <span class="attribute">background</span>:red; <span class="attribute">overflow</span>:hidden; &#125;</span><br><span class="line"><span class="selector-class">.div1</span><span class="selector-pseudo">:hover</span>&#123; <span class="attribute">overflow-y</span>:auto &#125;</span><br><span class="line"><span class="selector-class">.div2</span>&#123; <span class="comment">/* 子级 */</span> <span class="attribute">width</span>:<span class="number">100px</span>; <span class="attribute">margin-left</span>:<span class="number">20px</span>; <span class="attribute">height</span>:<span class="number">2000px</span>; &#125;</span><br></pre></td></tr></table></figure>
<h3 id="隐藏滚动条"><a href="#隐藏滚动条" class="headerlink" title="隐藏滚动条"></a>隐藏滚动条</h3><p>隐藏竖直滚动条，但页面依然可以滚动   兼容性：兼容 IE9及以上</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/* PC端 隐藏滚轮*/</span></span><br><span class="line"><span class="selector-tag">html</span>,<span class="selector-tag">body</span> &#123;<span class="attribute">height</span>: <span class="number">100%</span>;&#125;</span><br><span class="line"><span class="selector-tag">html</span> &#123;<span class="attribute">overflow</span>: hidden;&#125;</span><br><span class="line"><span class="selector-tag">body</span> &#123;<span class="attribute">overflow</span>: auto;<span class="attribute">width</span>: <span class="built_in">calc</span>(<span class="number">100vw</span> + <span class="number">20px</span>);&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">/* PE端 隐藏滚轮*/</span></span><br><span class="line">::-webkit-scrollbar &#123; <span class="attribute">display</span>: none; &#125;</span><br></pre></td></tr></table></figure>

<h3 id="蒙版弹窗滚动条不滚动"><a href="#蒙版弹窗滚动条不滚动" class="headerlink" title="蒙版弹窗滚动条不滚动"></a>蒙版弹窗滚动条不滚动</h3><p>通过点击出现弹窗后，通过js设置外部滚动条为隐藏</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 点击显示弹窗，设置外部 `css`为 `hidden`</span></span><br><span class="line">$(<span class="string">&#x27;.buttom&#x27;</span>).<span class="title function_">click</span>(<span class="keyword">function</span>(<span class="params"></span>)&#123;</span><br><span class="line">  $(<span class="string">&#x27;.shadow_box&#x27;</span>).<span class="title function_">show</span>()</span><br><span class="line">  $(<span class="variable language_">document</span>.<span class="property">body</span>).<span class="title function_">css</span>(&#123;<span class="string">&quot;overflow-x&quot;</span>:<span class="string">&quot;hidden&quot;</span>,<span class="string">&quot;overflow-y&quot;</span>:<span class="string">&quot;hidden&quot;</span>&#125;);</span><br><span class="line">&#125;)</span><br><span class="line"></span><br><span class="line"><span class="comment">// 点击蒙版，设置外部 `css` 为 `auto`</span></span><br><span class="line">$(<span class="string">&#x27;.shadow&#x27;</span>).<span class="title function_">click</span>(<span class="keyword">function</span>(<span class="params"></span>)&#123;</span><br><span class="line">    $(<span class="string">&#x27;.shadow_box&#x27;</span>).<span class="title function_">hide</span>()</span><br><span class="line">  $(<span class="variable language_">document</span>.<span class="property">body</span>).<span class="title function_">css</span>(&#123;<span class="string">&quot;overflow-x&quot;</span>:<span class="string">&quot;auto&quot;</span>,<span class="string">&quot;overflow-y&quot;</span>:<span class="string">&quot;auto&quot;</span>&#125;);</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>


<h2 id="设备的分类的参考"><a href="#设备的分类的参考" class="headerlink" title="设备的分类的参考"></a>设备的分类的参考</h2><h3 id="关于手机和-PC-的判断"><a href="#关于手机和-PC-的判断" class="headerlink" title="关于手机和 PC 的判断"></a>关于手机和 PC 的判断</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//如果是手机端则去百度，不是则去新闻</span></span><br><span class="line"><span class="variable language_">window</span>.<span class="property">location</span>.<span class="property">href</span> = <span class="regexp">/Android|webOS|iPhone|ipod|ipad|BlackBerry/i</span>.<span class="title function_">test</span>(navigator.<span class="property">userAgent</span>) ? <span class="string">&quot;https://www.baidu.com/&quot;</span> :  <span class="string">&quot;http://news.baidu.com/&quot;</span>;</span><br></pre></td></tr></table></figure>

<h3 id="关于屏幕大小属性参考"><a href="#关于屏幕大小属性参考" class="headerlink" title="关于屏幕大小属性参考"></a>关于屏幕大小属性参考</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"># 浏览器窗口大小（包括工具栏）</span><br><span class="line">window.outerHeight</span><br><span class="line">window.outerWidth</span><br><span class="line"></span><br><span class="line"># 窗口文档显示区（不包含滚动条）</span><br><span class="line">window.innerWidth</span><br><span class="line">window.innerHeight</span><br><span class="line"></span><br><span class="line"># 元素级内部大小（不包含滚动条）</span><br><span class="line">clientWidth</span><br><span class="line">clientHeight</span><br></pre></td></tr></table></figure>

<h3 id="关于手机横竖屏的判断"><a href="#关于手机横竖屏的判断" class="headerlink" title="关于手机横竖屏的判断"></a>关于手机横竖屏的判断</h3><blockquote>
<p>通过 <code>window.orientation</code> 属性进行判断， PC 端为 undefined，90或-90为横屏幕，剩下则是竖屏</p>
</blockquote>
<h2 id="功能的相关参考"><a href="#功能的相关参考" class="headerlink" title="功能的相关参考"></a>功能的相关参考</h2><h3 id="禁止用户使用页面后退"><a href="#禁止用户使用页面后退" class="headerlink" title="禁止用户使用页面后退"></a>禁止用户使用页面后退</h3><figure class="highlight js"><figcaption><span>不支持IE</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//防止页面后退</span></span><br><span class="line">history.<span class="title function_">pushState</span>(<span class="literal">null</span>, <span class="literal">null</span>, <span class="variable language_">document</span>.<span class="property">URL</span>);</span><br><span class="line"><span class="variable language_">window</span>.<span class="title function_">addEventListener</span>(<span class="string">&#x27;popstate&#x27;</span>, <span class="keyword">function</span> (<span class="params"></span>) &#123;</span><br><span class="line">    history.<span class="title function_">pushState</span>(<span class="literal">null</span>, <span class="literal">null</span>, <span class="variable language_">document</span>.<span class="property">URL</span>);</span><br><span class="line">&#125;);</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h3 id="js控制点击关闭当前页面"><a href="#js控制点击关闭当前页面" class="headerlink" title="js控制点击关闭当前页面"></a>js控制点击关闭当前页面</h3><p>浏览器出于安全策略的考虑，只允许Javascript 关闭由Javascript 打开的页面，所以当我们需要关闭当前页面的时候，你可以这样</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">a</span> <span class="attr">onClick</span>=<span class="string">&quot;window.opener=null;window.open(&#x27;&#x27;,&#x27;_self&#x27;);window.close();&quot;</span>&gt;</span>关闭<span class="tag">&lt;/<span class="name">a</span>&gt;</span></span><br></pre></td></tr></table></figure>
<blockquote>
<p>window.opener是一个可读可写的属性，返回对创建该窗口的 Window 对象的引用<br>window.opener.lose()可以关闭父级窗口<br>思路，先设置opener为空，当打开一个空的新窗口，关闭父级窗口，因为打开的是空，所有新的子页面不会出现</p>
</blockquote>
<h3 id="表单自动填入功能"><a href="#表单自动填入功能" class="headerlink" title="表单自动填入功能"></a>表单自动填入功能</h3><blockquote>
<p>在部分浏览器中,会默认开启自动完成功能。注意 属性 name 和 id 会影响改功能；</p>
</blockquote>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">&quot;text&quot;</span>/&gt;</span> </span><br><span class="line">// 当不存在name 或 id 的时候，自动完成不会开启，只有当其中一个出现的时候才会启动。</span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">form</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">&quot;email&quot;</span> <span class="attr">name</span>=<span class="string">&quot;email&quot;</span> <span class="attr">autocomplete</span>=<span class="string">&quot;off&quot;</span> /&gt;</span></span><br><span class="line">// 也可以通过 autocomplate 进行控制。</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">// 自动填写功能默认为黄色，下面的样式会重置它</span><br><span class="line"><span class="selector-tag">input</span>:-webkit-autofill,</span><br><span class="line">input:-webkit-autofill:hover, </span><br><span class="line">input:-webkit-autofill:focus,</span><br><span class="line">textarea:-webkit-autofill,</span><br><span class="line">textarea:-webkit-autofill:hover,</span><br><span class="line">textarea:-webkit-autofill:focus,</span><br><span class="line">select:-webkit-autofill,</span><br><span class="line">select:-webkit-autofill:hover,</span><br><span class="line">select:-webkit-autofill:focus &#123;</span><br><span class="line">  <span class="attribute">border</span>: <span class="number">1px</span> solid green;</span><br><span class="line">  -webkit-text-fill-<span class="attribute">color</span>: green;</span><br><span class="line">  -webkit-<span class="attribute">box-shadow</span>: <span class="number">0</span> <span class="number">0</span> <span class="number">0px</span> <span class="number">1000px</span> <span class="number">#000</span> inset;</span><br><span class="line">  <span class="attribute">transition</span>: background-color <span class="number">5000s</span> ease-in-out <span class="number">0s</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="html动态加载-js文件"><a href="#html动态加载-js文件" class="headerlink" title="html动态加载 js文件"></a>html动态加载 js文件</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">function</span> <span class="title function_">loadScript</span>(<span class="params">url,callback</span>)&#123;</span><br><span class="line">    <span class="keyword">var</span> script=<span class="variable language_">document</span>.<span class="title function_">createElement</span>(<span class="string">&quot;script&quot;</span>);</span><br><span class="line">    script.<span class="property">type</span>=<span class="string">&quot;text/javascript&quot;</span>;</span><br><span class="line">    <span class="keyword">if</span>(script.<span class="property">readyState</span>)&#123;</span><br><span class="line">        script.<span class="property">onreadystatechange</span>=<span class="keyword">function</span>(<span class="params"></span>)&#123;</span><br><span class="line">            <span class="keyword">if</span>(script.<span class="property">readyState</span>==<span class="string">&quot;load&quot;</span>||script.<span class="property">readyState</span>==<span class="string">&quot;complete&quot;</span>)&#123;</span><br><span class="line">                script.<span class="property">onreadystatechange</span>=<span class="literal">null</span>;</span><br><span class="line">                <span class="title function_">callback</span>();</span><br><span class="line">            &#125;;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">        script.<span class="property">onload</span>=<span class="keyword">function</span>(<span class="params"></span>)&#123;</span><br><span class="line">            <span class="title function_">callback</span>();</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    script.<span class="property">src</span>=url;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="title function_">loadScript</span>(<span class="string">&quot;jquery.js&quot;</span>,<span class="keyword">function</span>(<span class="params"></span>)&#123;</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;加载完成&#x27;</span>)</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>


<h3 id="prototype-原型改造"><a href="#prototype-原型改造" class="headerlink" title="prototype 原型改造"></a>prototype 原型改造</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 通过全局属性进行定义</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> a=<span class="variable language_">document</span>.<span class="title function_">getElementById</span>(<span class="string">&quot;en&quot;</span>)</span><br><span class="line">a.<span class="property">addClass</span>=<span class="keyword">function</span>(<span class="params">name</span>)&#123;</span><br><span class="line">    <span class="keyword">var</span> a=<span class="variable language_">this</span>.<span class="title function_">getAttribute</span>(<span class="string">&quot;class&quot;</span>)</span><br><span class="line">    <span class="keyword">if</span>(a)&#123;</span><br><span class="line">        a=a+<span class="string">&quot; &quot;</span>+name;</span><br><span class="line">        <span class="variable language_">this</span>.<span class="title function_">setAttribute</span>(<span class="string">&quot;class&quot;</span>,a)</span><br><span class="line">    &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">        <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="variable language_">this</span>)</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line">a.<span class="title function_">addClass</span>(<span class="string">&quot;name&quot;</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment">// 通过prototype进行定义</span></span><br><span class="line"></span><br><span class="line"><span class="title class_">String</span>.<span class="property"><span class="keyword">prototype</span></span>.<span class="property">lengths</span>=<span class="keyword">function</span>(<span class="params">name</span>)&#123;</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="variable language_">this</span>.<span class="property">length</span>)</span><br><span class="line">&#125;</span><br><span class="line"><span class="string">&quot;lenght&quot;</span>.<span class="title function_">lengths</span>()</span><br></pre></td></tr></table></figure>
  </article>
  <aside class="table-content" id="site-toc">
  <div class="table-content-title">
    <i class="fa fa-arrow-right fa-lg" id="site-toc-hide-btn"></i>
    <span>目录</span>
  </div>
  <div class="table-content-main">
    <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%A0%B7%E5%BC%8F%E7%9A%84%E5%A4%84%E7%90%86%E5%8F%82%E8%80%83"><span class="toc-text">样式的处理参考</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%86%85%E5%AE%B9%E8%BF%9B%E8%A1%8C%E5%BC%BA%E5%88%B6%E6%8D%A2%E8%A1%8C"><span class="toc-text">内容进行强制换行</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%A6%81%E6%AD%A2%E5%A4%8D%E5%88%B6%E9%A1%B5%E9%9D%A2%E6%96%87%E5%AD%97"><span class="toc-text">禁止复制页面文字</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%AF%B9%E5%86%85%E5%AE%B9%E8%BF%9B%E8%A1%8C%E7%BC%A9%E6%94%BE%E5%A4%84%E7%90%86"><span class="toc-text">对内容进行缩放处理</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%82%B9%E5%87%BB%E8%8E%B7%E5%8F%96%E7%84%A6%E7%82%B9%E5%92%8Ctab%E8%8E%B7%E5%8F%96%E7%84%A6%E7%82%B9"><span class="toc-text">点击获取焦点和tab获取焦点</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%8D%95%E8%A1%8C%E5%A4%9A%E8%A1%8C%E6%96%87%E6%9C%AC%E7%9A%84%E7%9C%81%E7%95%A5"><span class="toc-text">单行多行文本的省略</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#CONSOLE-%E4%BF%A1%E6%81%AF%E9%9B%86"><span class="toc-text">CONSOLE 信息集</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E9%A1%B5%E9%9D%A2%E5%8A%A8%E7%94%BB%E7%9A%84%E7%9B%B8%E5%85%B3%E5%8F%82%E8%80%83"><span class="toc-text">页面动画的相关参考</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%97%8B%E8%BD%AC%E5%8D%A1%E7%89%87"><span class="toc-text">旋转卡片</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%9A%82%E5%81%9C%E6%95%88%E6%9E%9C"><span class="toc-text">暂停效果</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%9B%BE%E7%89%87%E7%9A%84%E7%9B%B8%E5%85%B3%E5%A4%84%E7%90%86"><span class="toc-text">图片的相关处理</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%9B%BE%E7%89%87%E7%9A%84%E4%B8%8A%E4%BC%A0%E9%A2%84%E8%A7%88"><span class="toc-text">图片的上传预览</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%A4%A7%E5%9B%BE%E4%BB%8E%E6%A8%A1%E7%B3%8A%E5%88%B0%E6%B8%85%E6%99%B0"><span class="toc-text">大图从模糊到清晰</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%9B%BE%E7%89%87%E5%8A%A8%E6%80%81%E5%8A%A0%E8%BD%BDloading"><span class="toc-text">图片动态加载loading</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%BB%9A%E5%8A%A8%E6%9D%A1%E7%9A%84%E7%9B%B8%E5%85%B3%E5%A4%84%E7%90%86%E6%96%B9%E5%BC%8F"><span class="toc-text">滚动条的相关处理方式</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%BB%9A%E5%8A%A8%E6%9D%A1%E7%9A%84hover%E6%98%BE%E7%A4%BA"><span class="toc-text">滚动条的hover显示</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E9%9A%90%E8%97%8F%E6%BB%9A%E5%8A%A8%E6%9D%A1"><span class="toc-text">隐藏滚动条</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%92%99%E7%89%88%E5%BC%B9%E7%AA%97%E6%BB%9A%E5%8A%A8%E6%9D%A1%E4%B8%8D%E6%BB%9A%E5%8A%A8"><span class="toc-text">蒙版弹窗滚动条不滚动</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%AE%BE%E5%A4%87%E7%9A%84%E5%88%86%E7%B1%BB%E7%9A%84%E5%8F%82%E8%80%83"><span class="toc-text">设备的分类的参考</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%85%B3%E4%BA%8E%E6%89%8B%E6%9C%BA%E5%92%8C-PC-%E7%9A%84%E5%88%A4%E6%96%AD"><span class="toc-text">关于手机和 PC 的判断</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%85%B3%E4%BA%8E%E5%B1%8F%E5%B9%95%E5%A4%A7%E5%B0%8F%E5%B1%9E%E6%80%A7%E5%8F%82%E8%80%83"><span class="toc-text">关于屏幕大小属性参考</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%85%B3%E4%BA%8E%E6%89%8B%E6%9C%BA%E6%A8%AA%E7%AB%96%E5%B1%8F%E7%9A%84%E5%88%A4%E6%96%AD"><span class="toc-text">关于手机横竖屏的判断</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%8A%9F%E8%83%BD%E7%9A%84%E7%9B%B8%E5%85%B3%E5%8F%82%E8%80%83"><span class="toc-text">功能的相关参考</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%A6%81%E6%AD%A2%E7%94%A8%E6%88%B7%E4%BD%BF%E7%94%A8%E9%A1%B5%E9%9D%A2%E5%90%8E%E9%80%80"><span class="toc-text">禁止用户使用页面后退</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#js%E6%8E%A7%E5%88%B6%E7%82%B9%E5%87%BB%E5%85%B3%E9%97%AD%E5%BD%93%E5%89%8D%E9%A1%B5%E9%9D%A2"><span class="toc-text">js控制点击关闭当前页面</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%A1%A8%E5%8D%95%E8%87%AA%E5%8A%A8%E5%A1%AB%E5%85%A5%E5%8A%9F%E8%83%BD"><span class="toc-text">表单自动填入功能</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#html%E5%8A%A8%E6%80%81%E5%8A%A0%E8%BD%BD-js%E6%96%87%E4%BB%B6"><span class="toc-text">html动态加载 js文件</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#prototype-%E5%8E%9F%E5%9E%8B%E6%94%B9%E9%80%A0"><span class="toc-text">prototype 原型改造</span></a></li></ol></li></ol>
  </div>
</aside>

  
  
    <aside class="passage-copyright">
      <div>本文作者: 饿包子</div>
      
        <div>
          原文链接: 
          <a href="" target="_blank">https://lixianbin1.github.io/blog/2019/06/21/%E5%8A%9F%E8%83%BD%E4%B8%8E%E6%A0%B7%E5%BC%8F%E7%9A%84%E5%8F%82%E8%80%83%E5%92%8C%E5%A5%87%E6%80%9D%E5%A6%99%E6%83%B3/</a>
        </div>
      
      <div>
        版权声明: 本博客所有文章除特别声明外, 均采用 <a target="_blank" rel="noopener" href="https://creativecommons.org/licenses/by-nc-sa/4.0/">CC BY-NC-SA 4.0</a> 许可协议. 转载请注明出处!
      </div>
    </aside>
  
  
    <div class="passage-tags">
     
      <a href="/blog/tags/Javascript/"><i class="fa fa-tags"></i>Javascript</a>
    
    </div>
  
</div>

    </main>
    
      
<div class="site-comment-contanier" data-plateform="leancloud">
  
    <p id="site-comment-info">
      <i class="fa fa-spinner fa-spin"></i> 评论加载中
    </p>
    <div id="site-comment"></div>
  
</div>
    
    
<div class="site-footer-wrapper">
<!--
  <div class="footer-top">
    <a class="left" href="/blog/2019/06/21/%E5%89%8D%E7%AB%AF%E5%85%B3%E4%BA%8E%E6%95%B0%E6%8D%AE%E5%A4%84%E7%90%86%E7%9A%84%E7%9B%B8%E5%85%B3%E5%8F%82%E8%80%83/" data-enable="true">
      <i class="fa fa-arrow-left"></i>
    </a>
    <a class="right" href="/blog/2019/06/02/JS%20%E7%9A%84%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F%E4%BB%8B%E7%BB%8D%EF%BC%88%E4%B8%80%EF%BC%89/" data-enable="true">
      <i class="fa fa-arrow-right"></i>
    </a>
  </div>
-->
  <footer class="site-footer">
    
      
        <div class="site-footer-col">
          <h5 class="site-footer-title">网站推荐</h5>
          
            <span class="site-footer-item">
              <a href="https://tympanus.net/codrops/" target="_blank">Codrops</a>
            </span>
          
            <span class="site-footer-item">
              <a href="http://taobaofed.org/" target="_blank">淘宝前端团队(FED)</a>
            </span>
          
        </div>
      
        <div class="site-footer-col">
          <h5 class="site-footer-title">文档教程</h5>
          
            <span class="site-footer-item">
              <a href="https://es6.ruanyifeng.com/" target="_blank">ES6入门</a>
            </span>
          
            <span class="site-footer-item">
              <a href="https://developer.mozilla.org/zh-CN/docs/Web" target="_blank">MDN Web文档</a>
            </span>
          
        </div>
      
        <div class="site-footer-col">
          <h5 class="site-footer-title">兴趣前沿</h5>
          
            <span class="site-footer-item">
              <a href="https://threejs.org/" target="_blank">threejs</a>
            </span>
          
            <span class="site-footer-item">
              <a href="https://github.com/justadudewhohacks/face-api.js" target="_blank">face-api</a>
            </span>
          
        </div>
      
    
    <div class="site-footer-info">
      <i class="fa fa-clock-o"></i> 本站已稳定运行<span id="site-time"></span>
    </div>
    
      <div class="site-footer-info">
        <i class="fa fa-paw"></i> 您是本站第 <span id="site-count"></span> 位访客
      </div>
    
    
      <div class="site-footer-info">
        <i class="fa fa-at"></i> Email: xianbin.me@qq.com
      </div>
    
<!--     <div class="site-footer-info">
      <i class="fa fa-copyright"></i> 
      2019 <a href="https://github.com/dongyuanxin/theme-ad/" target="_blank">Theme-AD</a>.
      Created by <a href="https://godbmw.com/" target="_blank">GodBMW</a>.
      All rights reserved.
    </div> -->
  </footer>
</div>
    <div id="site-layer" style="display:none;">
  <div class="site-layer-content">
    <div class="site-layer-header">
      <span class="site-layer-header-title" id="site-layer-title"></span>
      <i class="fa fa-close" id="site-layer-close"></i>
    </div>
    <div class="site-layer-body" id="site-layer-container">
      <div class="site-layer-input" id="site-layer-search" style="display: none;">
        <input type="text">
        <i class="fa fa-search"></i>
      </div>
      
        <div class="site-layer-reward" id="site-layer-reward" style="display: none;">
          
            <div>
              <img src="/blog/images/wechat.png" alt="WeChat">
              
                <p>WeChat</p>
              
            </div>
          
            <div>
              <img src="/blog/images/alipay.png" alt="AliPay">
              
                <p>AliPay</p>
              
            </div>
          
        </div>
      
      <div id="site-layer-welcome" style="display:none;"></div>
    </div>
  </div>
</div>
    

<div class="bottom-bar">

  <div class="bottom-bar-left">
<!--
    <a href="/blog/2019/06/21/%E5%89%8D%E7%AB%AF%E5%85%B3%E4%BA%8E%E6%95%B0%E6%8D%AE%E5%A4%84%E7%90%86%E7%9A%84%E7%9B%B8%E5%85%B3%E5%8F%82%E8%80%83/" data-enable="true">
      <i class="fa fa-arrow-left"></i>
    </a>
    <a href="/blog/2019/06/02/JS%20%E7%9A%84%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F%E4%BB%8B%E7%BB%8D%EF%BC%88%E4%B8%80%EF%BC%89/" data-enable="true">
      <i class="fa fa-arrow-right"></i>
    </a>
-->
  </div>

  
  
  
  <div class="bottom-bar-right">
    <a href="javascript:void(0);" data-enable="true" id="site-toc-show-btn">
      <i class="fa fa-bars"></i>
    </a>
    
      <a href="#site-comment" data-enable="true">
        <i class="fa fa-commenting"></i>
      </a>
    
    <a href="javascript:void(0);" id="site-toggle-share-btn">
      <i class="fa fa-share-alt"></i>
    </a>
    
    <a href="javascript:void(0);" id="back-top-btn">
      <i class="fa fa-chevron-up"></i>
    </a>
  </div>
</div>
    <div id="share-btn">
  
  
  
    <a id="share-btn-weibo" href="javascript:void(0);" target="_blank">
      <i class="fa fa-weibo"></i>
    </a>
  
  
    <a id="share-btn-qq" href="javascript:void(0);" target="_blank">
      <i class="fa fa-qq"></i>
    </a>
  
  
</div>
    





    
  </body>
</html>